package com.pwc.conversionTool.dao;

import java.util.List;

import com.googlecode.objectify.Key;
import com.pwc.conversionTool.entity.Account;
import com.pwc.conversionTool.entity.Task;
import com.pwc.conversionTool.entity.TaskFlow;

import static com.pwc.conversionTool.entity.service.OfyService.ofy;

public class TaskDao {

	
	public Key<TaskFlow> saveTaskFlow(TaskFlow taskFlow)
	{
		return ofy().save().entity(taskFlow).now();
	}

	public TaskFlow getTaskFlowById(Long taskFlowId) {
		
		return ofy().load().type(TaskFlow.class).id(taskFlowId).now();
	}

	public Task getTaskById(Long id) {
		return ofy().load().type(Task.class).id(id).now();
	}

	public Key<Task> saveTask(Task task) {
		
		return ofy().save().entity(task).now();
	}

	public List<Task> getTaskFlowByTaskFlowId(Key<TaskFlow> taskFlowKey) {
		return ofy().load().type(Task.class).filter("taskFlowKey", taskFlowKey).list();
	}

	public void deleteTaskById(Long id) {
		
		ofy().delete().type(Task.class).id(id).now();
		
	}

	public Task getTaskByKey(Key<Task> TaskKey) {
		
		return ofy().load().key(TaskKey).now();		 
	}

	public TaskFlow getTaskFlowByKey(Key<TaskFlow> taskFlowKey) {
		
		return ofy().load().key(taskFlowKey).now();
		
		
	}

	public Task getPreviousTask(Key<Task> key) {
		
		return ofy().load().type(Task.class).filter("nextTaskKey", key).first().now();
		
	}

	public List<TaskFlow> getTaskFlowList(Account account) {
		
		return ofy().load().type(TaskFlow.class).filter("account",account.getKey()).order("-createdDate").list();
	}
	
	
	
}
